
package com.catsic.logs.specification;

import java.util.Date;

import javax.persistence.criteria.Path;

import org.apache.commons.lang3.StringUtils;

import com.catsic.base.specification.BaseSpec;
import com.catsic.base.specification.QueryWraper;
import com.catsic.logs.condition.LogsCondition;
import com.catsic.logs.entity.Logs;
/**
 * ClassName: LogsSpec
 * Description: LogsSpec
 * date: 2013年4月28日 下午2:30:29
 * author: yangyd
 */
public class LogsSpec extends BaseSpec<Logs> {

	public LogsSpec(LogsCondition condition){
		super(condition);
	}
	
	/**
	 * @see com.catsic.core.specification.BaseSpec#addCondition(com.catsic.core.specification.QueryWraper)
	 */
	@Override
	protected void addCondition(QueryWraper<Logs> queryWraper) {
		LogsCondition condition = (LogsCondition) getCondition();
		
		if(StringUtils.isNotBlank(condition.getOrganCode())){
			Path<String> fieldPath = queryWraper.getRoot().get("organCode");
			addLikeConditionSuffix(queryWraper, fieldPath, condition.getOrganCode());
		}
		addLikeCondition(queryWraper, "organName");
		addLikeCondition(queryWraper, "module");
		addLikeCondition(queryWraper, "operation");
		addLikeCondition(queryWraper, "createName");
		Path<Date> createTime = queryWraper.getRoot().get("createTime");
		if(condition.getStartDate() != null){
			queryWraper.addPredicate(queryWraper.getCb().greaterThanOrEqualTo(createTime, condition.getStartDate()));
		}
		
		if(condition.getEndDate() != null){
			queryWraper.addPredicate(queryWraper.getCb().lessThanOrEqualTo(createTime, condition.getEndDate()));
		}
	}
}
